package com.wingscode.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.Query;
import com.wingscode.modules.sys.dao.BuildQualDao;
import com.wingscode.modules.sys.entity.BuildQualEntity;
import com.wingscode.modules.sys.service.BuildQualService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;


/**
 * 资质
 *
 * @author yan
 */
@Service("buildQualService")
public class BuildQualServiceImpl extends ServiceImpl<BuildQualDao, BuildQualEntity> implements BuildQualService {

	@Override
    public PageUtils queryPage(Map<String, Object> params) {
		Integer nameId = null, grade = null, qualType = null, state = null, qualFlag = null;
		if (params.containsKey("nameId") && params.get("nameId") != null && !params.get("nameId").toString().isEmpty())
			nameId = Integer.parseInt((String) params.get("nameId"));
		if (params.containsKey("grade") && params.get("grade") != null && !params.get("grade").toString().isEmpty())
			grade = Integer.parseInt((String) params.get("grade"));
		if (params.containsKey("qualType") && params.get("qualType") != null && !params.get("qualType").toString().isEmpty())
			qualType = Integer.parseInt((String) params.get("qualType"));
		if (params.containsKey("state") && params.get("state") != null && !params.get("state").toString().isEmpty())
			state = Integer.parseInt((String) params.get("state"));
		if (params.containsKey("qualFlag") && params.get("qualFlag") != null && !params.get("qualFlag").toString().isEmpty())
			qualFlag = Integer.parseInt((String) params.get("qualFlag"));

        IPage<BuildQualEntity> page = this.baseMapper.queryAll(new Query<BuildQualEntity>().getPage(params), nameId, grade, qualType, state, qualFlag);

        return new PageUtils(page);
    }
	
	@Override
	public void delete(Long[] ids){
		this.removeByIds(Arrays.asList(ids));
	}

	@Override
	public BuildQualEntity getByGrade(Integer nameId, Integer grade) {
		List<BuildQualEntity> list = this.baseMapper.getByGrade(nameId, grade);
		if (list != null && list.size() > 0)
			return list.get(0);

		return null;
	}

	@Override
	public List<BuildQualEntity> getBuildQual(Integer nameId, Integer grade, Integer qualType) {
		return this.baseMapper.getBuildQual(nameId, grade, qualType);
	}
}
